package array.leetcode_349;

import java.util.HashSet;
import java.util.Set;

public class Intersection {
    public static int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set = new HashSet<>();
        Set<Integer> resSet = new HashSet<>();
        for (int i : nums1) {
            set.add(i);
        }
        for (int i : nums2) {
            if(set.contains(i)){
                resSet.add(i);
            }
        }
        //将set转换成数组
        int i = 0;
        int[] res = new int[resSet.size()];
        for (Integer integer : resSet) {
            res[i++] = integer;
        }
        return res;
    }
}
